import { WebMapTileServiceImageryProvider } from "cesium";
import { normalize } from "../utils/common";
export default {
	props: {
		layerConfig: {
			default: () => {
				return {};
			},
		},
	},
	data() {
		return {
			layerSettings: {},
		};
	},
	created() {
		this.viewer = this.$parent.viewer;
		this.eventBus = this.$parent.eventBus;
		this.create();
	},
	beforeDestroy() {
		this.remove();
	},
	methods: {
		create() {
			const provider = new WebMapTileServiceImageryProvider(normalize(this.layerSettings));
			this.imgLayer = this.viewer.imageryLayers.addImageryProvider(provider);
			Object.assign(this.imgLayer, normalize(this.layerConfig));
		},
		remove() {
			this.viewer.imageryLayers.remove(this.imgLayer, true);
		},
	},
};
